package com.dubbo;

public class DeleteDuplicates {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummy = new ListNode();
        dummy.next = head;
        ListNode pre = head;
        ListNode tail = head;
        while (tail != null) {
            tail = tail.next;
            while (tail != null && pre.val == tail.val) {
                tail = tail.next;
            }

            if (pre == head) {
                head = tail;
            }
            pre = tail;
        }
        return head;
    }
}


class ListNode {
 int val;
 ListNode next;
 ListNode() {}
 ListNode(int val) { this.val = val; }
 ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}

